#ifndef EDGE_H
#define EDGE_H
#include<QGraphicsLineItem>
#include<QGraphicsTextItem>
#include<QPen>
#include<QFont>
#include<QBrush>

class Edge;
class Node:public QGraphicsEllipseItem
{
public:
    int size=50;
    int x,y;
    QPointF pos;//节点的坐标
    int id;
    Edge* edge;//节点的边
    QGraphicsTextItem *name;
    Node();
    Node(QPointF p)//node的中心坐标
    {
        edge = nullptr;
        pos=p;
        x=pos.x();
        y=pos.y();
        this->setRect(0,0,size,size);
        this->setPos(QPointF(p.x()-size/2,p.y()-size/2));
        this->setFlags(QGraphicsItem::ItemIsSelectable|
                            QGraphicsItem::ItemIsFocusable
                            );
        this->setBrush(QBrush(QColor("#81ecec")));
        name=new QGraphicsTextItem;
        name->setDefaultTextColor(Qt::black);

        name->setFont(QFont("宋体",10));
        //name->setFlags(QGraphicsItem::ItemIsSelectable);
        name->setPos(QPointF(p.x()-size/2-18,p.y()-size/2-18));
        name->setTextInteractionFlags(Qt::TextEditorInteraction);
        name->setZValue(2);

    }
    QPointF POS()
    {
        return pos;
    }

private:


};

class Edge: public QGraphicsLineItem
{
public:
    Node *start;//边的起点
    Node * end;//边的终点
    Edge * next;//下一条边
    int s,e;
    QGraphicsTextItem *weight;
    Edge();
    Edge(Node *s,Node* e)
    {
        start=s;
        end=e;
        next = nullptr;
        QPen pen(QColor("#a29bfe"));
        pen.setWidth(8);
        pen.setStyle(Qt::DashLine);
        pen.setJoinStyle(Qt::RoundJoin);//线条连接处圆角
        pen.setCapStyle(Qt::RoundCap);//端点风格圆角
        setPen(pen);
        setFlags(
                       QGraphicsItem::ItemIsFocusable
                       );
        setZValue(-1);//让线条位于最下层


        QPointF ss=s->POS();
        QPointF ee=e->POS();
        qreal x=(ss.x()+ee.x())/2;
        qreal y=(ss.y()+ee.y())/2;
        QPointF cc=QPointF(x,y);
        weight=new QGraphicsTextItem;


        weight->setPos(cc);
        weight->setDefaultTextColor(Qt::black);
        weight->setFont(QFont("宋体",12));
        //weight->setFlags(QGraphicsItem::ItemIsMovable);
        weight->setTextInteractionFlags(Qt::TextEditorInteraction);
        weight->setZValue(2);

    }
    Edge(Node* s )
    {
        start=s;
        next = nullptr;
        QPen pen(QColor("#a29bfe"));
        pen.setWidth(8);
        pen.setStyle(Qt::DashLine);
        pen.setJoinStyle(Qt::RoundJoin);//线条连接处圆角
        pen.setCapStyle(Qt::RoundCap);//端点风格圆角
        setPen(pen);
        setFlags(
                       QGraphicsItem::ItemIsFocusable
                       );
        setZValue(-1);//让线条位于最下层
        weight=new QGraphicsTextItem;
        weight->setPlainText(QString::number(0));


        weight->setDefaultTextColor(Qt::black);
        weight->setFont(QFont("宋体",12));
        //weight->setFlags(QGraphicsItem::ItemIsMovable);
        weight->setTextInteractionFlags(Qt::TextEditorInteraction);
        weight->setZValue(2);
    }

private:

};



#endif // EDGE_H

